﻿using System;
using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using Silvermoon.OpenGL;
using Silvermoon.OpenGL.Native;
using System.Drawing;
using Silvermoon.Images;
using Silvermoon.UI;

namespace Testing.Pages
{
    public class LabelTest : DemoWindowBase
    {
        const string text = "Silvermoon requires hardware support for open gl and expects the libGLES_CM.dll to be available. However, in the source code is a software rendering replacement available, but this is really not recommended, unless you want to deal with 0.3fps instead of 25fps!" +
            "\nThe beta version works with a resolution of 192dpi, which is the standard for actual mobile phones. (192dpi are used with resolutions of 480x800, 480x640 or similar, while 96dpi is used for resolutions of 240x400)." +
            "\nHowever, it also works with 96dpi but it is not yet optimized and needs alternative images to fit for smaller resolutions." +
            "\n\nSilvermoon was developed (and being in progess to be in development) on a Sony Ericsson X1 phone.";

        private Label label;

        public LabelTest()
        {
            SetTransition(350, TransitionMask.Zoom | TransitionMask.Fade, TransitionMask.Explode | TransitionMask.Fade);
            //sprite1 = new TextSprite { Text = "abcdefg", ClipSize = new Size(1024, 1024), Alignment= Alignment.Near, LineAlignment = Alignment.Near };
            //sprite2 = new TextSprite2 { Text = "abcdefg", Size = new Size(1024, 1024), Alignment= Alignment.Near, LineAlignment = Alignment.Near };
            label = new Label
            {
                FontScale = 0.75f,
                Text = text,
                Margin = new Margin(10, 58, 10, 10),
                Alignment = Alignment.Near,
                LineAlignment = Alignment.Near,
                Color = Color.Yellow,
                LineMode = LineMode.WordWrap
            };
            Controls.Add(label);

            Slider slider = new Slider { Margin = new Margin(10, 5, 10, null), Height = 48, Minimum = 40, Maximum = 400 };
            Controls.Add(slider);
            slider.ValueChanged += new EventHandler(slider_ValueChanged);


            if (Toolbar != null) Toolbar.Dispose();
            Toolbar = new Toolbar
            (
                new ToolbarButton(SysImages.Cancel, OnTap),
                new ToolbarButton(SysImages.Add, OnAdd)
            );

        }

        void slider_ValueChanged(object sender, EventArgs e)
        {
            Slider slider = sender as Slider;
            // label.Skew = slider.Value;
            label.FontScale = (float)slider.Value / 100F;
        }


        public void OnTap(object sender, TapEventArgs e)
        {

            switch (label.Alignment)
            {
                case Alignment.Near: label.Alignment = Alignment.Center; break;
                case Alignment.Center: label.Alignment = Alignment.Far; break;
                case Alignment.Far: label.Alignment = Alignment.Near; break;
            }
        }

        public void OnAdd(object sender, TapEventArgs e)
        {
            switch (label.CharSpace)
            {
                case 0: label.CharSpace = 4; break;
                case 4: label.CharSpace = 10; break;
                case 10: label.CharSpace = 15; break;
                case 15: label.CharSpace = 20; break;
                case 20: label.CharSpace = -3; break;
                case -3: label.CharSpace = -1; break;
                case -1: label.CharSpace = 0; break;
            }
        }
    }
}
